<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>后台页面</title>
  <link rel="stylesheet" type="text/css" href="../js/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo">首页</div>
    <!-- 头部区域（可配合layui已有的水平导航） -->
    
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item">
        <a href="javascript:;">
          <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
          贤心
        </a>
        <dl class="layui-nav-child">
          <dd><a href="">基本资料</a></dd>
          <dd><a href="">安全设置</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item"><a href="">退出</a></li>
    </ul>
  </div>
  
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll" id="menuitem">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree layui-inline" lay-shrink="all" lay-filter="test">
        <li class="layui-nav-item layui-nav-itemed">
          <a class="" href="javascript:;">权限管理</a>
          <dl class="layui-nav-child">
            <dd><a href="javascript:;" code="liebiao1" url="frist.html">菜单管理</a></dd>
            <dd><a href="javascript:;" code="liebiao2">列表二</a></dd>
            <dd><a href="javascript:;" code="liebiao3">列表三</a></dd>
            <dd><a href="javascript:;" code="liebiao4">超链接</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">解决方案</a>
          <dl class="layui-nav-child">
            <dd><a href="javascript:;">列表一</a></dd>
            <dd><a href="javascript:;">列表二</a></dd>
            <dd><a href="javascript:;">超链接</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item"><a href="javascript:;">云市场</a></li>
        <li class="layui-nav-item"><a href="javascript:;">发布商品</a></li>
      </ul>
    </div>
  </div>
  
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;" id="zhuti">
		
		<div id="layui-tab" class="layui-tab" lay-filter="demo" lay-allowclose="true" style="display:none"> 
		  <ul class="layui-tab-title">
			
		  </ul>
		  <div class="layui-tab-content">
			
		  </div>
		</div>
	</div>
  </div>
  
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    © layui.com - 底部固定区域
  </div>
</div>
<script src="../js/jquery-3.3.1.js" type="text/javascript"></script>
<script src="../js/layui/layui.js" type="text/javascript"></script>
<script>
//JavaScript代码区域
	layui.use(['layer', 'element'], function(){
		var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
		var layer = layui.layer;
		//监听导航点击
		element.on('nav(test)', function(elem){
			$("#layui-tab").attr("style","");
			console.log(elem)
			var title = $(elem).text();
			var code = $(elem).attr("code");
			var url = $(elem).attr("url");
			if(!code){
				return;
			}
			//$("#iframe").attr("src",url);
			if($("#zhuti").find("li[lay-id='"+code+"']").length==0 ){
				element.tabAdd('demo', {
				  title: title
				  ,content: '<div id="iframe'+code+'" data-frameid="'+code+'" style="width:100%;height:100%"></div>' //支持传入html
				  ,id: code
				});
				$("#iframe"+code).load("frist")
				element.tabChange('demo', code);
			}else{
				element.tabChange('demo', code);
			}
		});
		element.on('tab(test)', function(data){
			console.log(data);
		});
  
	});
	
	}
</script>
</body>
</html>